package com.itheima.config;

import jakarta.annotation.PostConstruct;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;

@Configuration
public class MqConfig {
    @Autowired
    private RabbitTemplate rabbitTemplate;

    @PostConstruct
    public void init() {
        rabbitTemplate.setReturnsCallback(returns -> {
            System.out.println("消息发送失败，失败原因：" + returns.getReplyText());
            System.out.println("消息发送失败，消息：" + returns.getMessage());
            System.out.println("消息发送失败，交换机：" + returns.getExchange());
            System.out.println("消息发送失败，路由键：" + returns.getRoutingKey());
        });
    }
}
